package com.robot.merchant.controller;

import com.alibaba.fastjson.JSON;
import com.robot.merchant.pojo.Company;
import com.robot.merchant.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wuyunbin
 */
@RestController
@CrossOrigin
@RequestMapping("/company")
public class CompanyJsonController {
    @Autowired
    private CompanyService companyService;
    /**
     * 通过id查找商户
     *
     * @param id
     * @return
     */
    @GetMapping(value = "third/findCompanyById/{id}", produces = "application/json; charset=utf-8")
    public String thirdFindCompanyById(@PathVariable String id) {
        return JSON.toJSONString(companyService.findById(id));
    }

    /**
     * 通过agentId查找商户
     *
     * @param agentId
     * @return
     */
    @GetMapping(value = "third/findCompaniesByAgentId/{agentId}", produces = "application/json; charset=utf-8")
    public String thirdFindCompaniesByAgentId(@PathVariable String agentId) {
        return JSON.toJSONString(companyService.findAllByAgentId(agentId));
    }

    /**
     * 增加company
     *
     * @param company
     */
    @PostMapping("third/addCompany")
    public void thirdAddCompany(@RequestBody String company) {
        companyService.add(JSON.parseObject(company, Company.class));
    }
}
